package gui;

import ptolemy.actor.gui.Effigy;
import ptolemy.actor.gui.Tableau;
import ptolemy.actor.gui.TableauFactory;

import ptolemy.kernel.util.*;

import java.util.LinkedList;

import javax.swing.JFrame;
import java.awt.Toolkit;
import java.awt.Dimension;
import java.awt.Frame;

//////////////////////////////////////////////////////////////////////////
//// VerifierTableau
/**

@author  Ivan Jeukens
@version v 0.1 24/01/2002
*/
public class VerifierTableau extends Tableau {

    public VerifierTableau(Workspace workspace) 
            throws IllegalActionException, NameDuplicationException {
        super(workspace);
    }

    public VerifierTableau(VerifierEffigy container, String name)
            throws IllegalActionException, NameDuplicationException {
        super(container, name);

        _frame = new VerifierFrame();
        super.setEditable(false);
        setFrame(_frame);
        //_frame.setTableau(this);
    }

    ///////////////////////////////////////////////////////////////////
    ////                         public methods                    ////

    public void setEditable(boolean flag) {
        super.setEditable(flag);
    }

    public void show() {
        JFrame frame = getFrame();
        if(frame != null) {
            Toolkit tk = Toolkit.getDefaultToolkit();

            int w = 4*tk.getScreenSize().width/5;
            int h = tk.getScreenSize().height/3;
            frame.setSize(w, h);
            frame.getRootPane().setPreferredSize(new Dimension(w,h));
            frame.getContentPane().setSize(w,h);

            frame.setLocation(50, 30);

            frame.pack();
            frame.setVisible(true);

            frame.setState(Frame.NORMAL);
            frame.toFront();
        }
    }

    public void initialize() {

    }

    public void initializeFrame(VerifierEffigy effigy) {
        _frame.initialize(effigy);
    }

    public LinkedList getSelectedMocs() {
       //return _frame.getSelectedMocs();
       return new LinkedList();
    }

    ///////////////////////////////////////////////////////////////////
    ////                        private methods                    ////

    ///////////////////////////////////////////////////////////////////
    ////                         private variables                 ////

    private VerifierFrame _frame;

    ///////////////////////////////////////////////////////////////////
    ////                         inner classes                     ////

    public static class Factory extends TableauFactory {

	public Factory(NamedObj container, String name)
                throws IllegalActionException, NameDuplicationException {
	    super(container, name);
	}

        ///////////////////////////////////////////////////////////////////
        ////                         public methods                    ////

	public Tableau createTableau(Effigy effigy) throws Exception {
            if(effigy instanceof VerifierEffigy) {
                VerifierTableau tableau = 
                    (VerifierTableau) effigy.getEntity("VerifierTableau");
                if(tableau == null) {
                    tableau = new VerifierTableau((VerifierEffigy) effigy, 
                        "VerifierTableau");
                }
                tableau.setEditable(effigy.isModifiable());
                tableau.initialize();
                tableau.initializeFrame((VerifierEffigy)effigy);

                return tableau;
	    } 
            else {
                return null;
            }
	}
    }
}
